package safrain.nodelet.template;

import java.util.ArrayList;
import java.util.List;

import safrain.nodelet.structure.FieldInfo;
import safrain.nodelet.structure.FieldType;
import safrain.nodelet.structure.Structure;
import safrain.nodelet.template.field.ReferenceField;
import safrain.nodelet.template.field.TemplateValue;
import safrain.nodelet.template.field.ValueField;

public class ObjectTemplate {
	public Structure structure;
	public List<ValueField<Template>> valueFields = new ArrayList<ValueField<Template>>();

	public ObjectTemplate(Structure structure) {
		this.structure=structure;
//		List<FieldInfo> fieldInfoList = structure
//				.getFieldInfoList(Template.class);
//		for (FieldInfo fieldInfo : fieldInfoList) {
//			valueFields.add(ValueField.<Template> getValueField(fieldInfo));
//		}
	}

	/**
	 * 设置模板值
	 */
	public void setValue(String name, Object value) {
		
		
		
		
		int size = valueFields.size();
		for (int i = 0; i < size; i++) {
			ValueField<Template> valueField = valueFields.get(i);
			if (valueField.getFieldInfo().fieldName.equals(name)) {
				// 如果是一般的值，直接赋值
				valueField.setValue(value);
				if (valueField instanceof ReferenceField) {
					ReferenceField<Template> referenceField = (ReferenceField<Template>) valueField;
					if (referenceField.value  instanceof TemplateValue) {

					}
				}

				// 如果是一个Template

				// 如果是List或者Map

			}
		}
	}

	public void set(Object obj) {
		int size = valueFields.size();
		for (int i = 0; i < size; i++) {
			valueFields.get(i).set(obj);
		}
	}

}
